package cn.sdut.training.web.action;

import java.util.List;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;

import cn.sdut.training.domain.Tag;
import cn.sdut.training.service.TrainingService;

public class TagAction extends ActionSupport {

	private static final long serialVersionUID = -8270330086833281601L;

	private Long id;// 接受TagId，用于编辑
	private Tag tag;
	private List<Tag> tagList;
	
	@Resource
	private TrainingService trainingService;

	//-----------------------------------------------------------
	/**
	 * 保存
	 */
	public String save(){
		trainingService.saveTag(tag);
		return "toList";
	}
	
	/**
	 * 删除
	 */
	public String delete(){
		trainingService.deleteTag(id);
		return "toList";
	}
	
	/**
	 * 转向编辑页面
	 */
	public String toEditPage(){
		tag = trainingService.getTagById(id);
		return "toEditPage";
	}
	
	/**
	 * 执行更新 
	 */
	public String edit(){
		trainingService.updateTag(tag);
		return "toList";
	}
	
	/**
	 * 转向列表页面
	 * @return
	 */
	public String toListPage(){
		tagList = trainingService.findAllTags();
		return "toListPage";
	}
	
	//-----------------------------------------------------------
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Tag getTag() {
		return tag;
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	public List<Tag> getTagList() {
		return tagList;
	}

	public void setTagList(List<Tag> tagList) {
		this.tagList = tagList;
	}

}
